package com.luge.utils;

public class TimeUtil {

	public static String intToStr(int duration) {
		StringBuilder mBuilder = new StringBuilder();
		if (duration / 3600 > 0) {
			int hour = duration % 60 % 60;
			int minute = duration % 60;
			int second = (duration - minute * 60) % 60;
			mBuilder = hour >= 10 ? mBuilder.append(hour).append(":")
					: mBuilder.append("0").append(hour).append(":");
			mBuilder = minute >= 10 ? mBuilder.append(minute).append(":")
					: mBuilder.append("0").append(minute).append(":");
			mBuilder = second >= 10 ? mBuilder.append(second) : mBuilder
					.append("0").append(second);
		} else {
			int minute = duration / 60;
			int second = (duration - minute * 60) % 60;
			mBuilder = minute >= 10 ? mBuilder.append(minute).append(":")
					: mBuilder.append("0").append(minute).append(":");
			mBuilder = second >= 10 ? mBuilder.append(second) : mBuilder
					.append("0").append(second);
		}
		return mBuilder.toString();
	}

	public static int strToInt(String duration) {
		String[] times = duration.split(":");
		if (times.length == 2) {
			int minute = Integer.valueOf(times[0]) % 60;
			int second = Integer.valueOf(times[1]) % 60;
			return minute * 60 + second;
		} else if (times.length == 3) {
			int hour = Integer.valueOf(times[0]) % 60;
			int minute = Integer.valueOf(times[1]) % 60;
			int second = Integer.valueOf(times[2]) % 60;
			return hour * 3600 + minute * 60 + second;
		}
		return 0;
	}
}
